using System.Linq.Expressions;

namespace Universal.Domain.Repositories;

/// <summary>
/// 通用仓储接口
/// </summary>
public interface IRepository<T>
{
    //获取所有(不包含导航属性)
    Task<IEnumerable<T>> GetAllAsync();

    //获取单个(不包含导航属性)
    Task<T?> GetByIdAsync(Guid id);

    // 新增
    Task<T> AddAsync(T entity);

    //删除
    Task DeleteAsync(T entity);

    // 更新
    Task UpdateAsync(T entity);

    // 模糊查询
    IQueryable<T> Query();

    /// <summary>
    /// 根据id获取单个(包含导航属性)
    /// </summary>
    /// <param name="id">id</param>
    /// <param name="includes">包含的导航属性</param>
    /// <returns></returns>
    Task<T?> GetByIdWithIncludesAsync(Guid id, params Expression<Func<T, object>>[] includes);


    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="pageIndex">页码</param>
    /// <param name="pageSize">每页条数</param>
    /// <param name="includes">包含的导航属性</param>
    /// <returns>分页数据</returns>
    Task<(IEnumerable<T> Items, int TotalCount)> GetPagedAsync(
    int pageIndex, int pageSize, params Expression<Func<T, object>>[] includes);


}